package com.feiyuan.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


import com.feiyuan.modules.sys.entity.RoleEntity;
import com.feiyuan.modules.sys.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.feiyuan.modules.sys.entity.UserEntity;
import com.feiyuan.modules.sys.service.UserService;
import com.feiyuan.common.utils.PageUtils;
import com.feiyuan.common.utils.ResponseUtils;



/**
 * 
 *
 * @author Xupf
 * @email xupengfei131276@126.com
 * @date 2024-03-01 14:51:34
 */
@RestController
@RequestMapping("/admin/sys/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sys:user:list")
    public ResponseUtils list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return ResponseUtils.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:user:info")
    public ResponseUtils info(@PathVariable("id") Long id){
		UserEntity user = userService.getByIdInfo(id);

        return ResponseUtils.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:user:save")
    public ResponseUtils save(@RequestBody UserEntity user){
		userService.saveUser(user);

        return ResponseUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:user:update")
    public ResponseUtils update(@RequestBody UserEntity user){
        user.setUpdateTime(new Date());
		userService.updateByIdUser(user);

        return ResponseUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:user:delete")
    public ResponseUtils delete(@RequestBody Long[] ids){
		userService.removeByIdsUser(Arrays.asList(ids));

        return ResponseUtils.ok();
    }

    @GetMapping("/selectAllRole")
    public ResponseUtils selectAllRole() {
        List<RoleEntity> roleList = roleService.list();
        return new ResponseUtils().put("roles", roleList);
    }

}
